package com.group.yztcedu.playlive.utils;

import android.util.Log;

import com.group.yztcedu.playlive.bean.HomeBean;
import com.group.yztcedu.playlive.bean.HomeChannelsBean;
import com.group.yztcedu.playlive.bean.LoadMoreBean;
import com.group.yztcedu.playlive.bean.LoadMoreLivesBean;
import com.group.yztcedu.playlive.bean.PlayVideoBean;

import java.util.HashMap;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class HttpUtils {
    private static HttpUtils instance;
    private HttpUtils(){
    }
    public static synchronized HttpUtils getInstance(){
        if(instance==null){
            instance= new HttpUtils();
        }
        return instance;
    }
    public interface HttpCallBack<T>{
        void onSuccess(T t);
        void onFail();
    }
    //首页
    public void getHomeBeanData(HashMap<String,String> params,final HttpCallBack<HomeBean> beanHttpCallBack){
        Call<HomeBean> homeBeanCall = RetrofitHelper
                .getInstance()
                .createRetrofitService(BeanService.class)
                .getHome(params);
        homeBeanCall.enqueue(new Callback<HomeBean>() {
            @Override
            public void onResponse(Call<HomeBean> call, Response<HomeBean> response) {
                HomeBean bean = response.body();
                for (HomeChannelsBean homeDataBean : bean.getData().getChannels()) {
                    Log.d("-----", "" + homeDataBean.getChannelName());
                }
                beanHttpCallBack.onSuccess(response.body());
            }

            @Override
            public void onFailure(Call<HomeBean> call, Throwable t) {
                beanHttpCallBack.onFail();
            }
        });
    }
    //首页穿越火线加载更多
    public void getFireData(HashMap<String,String> params,final HttpCallBack<LoadMoreBean> beanHttpCallBack){
        Call<LoadMoreBean> homeBeanCall = RetrofitHelper
                .getInstance()
                .createRetrofitService(BeanService.class)
                .getFire(params);
        homeBeanCall.enqueue(new Callback<LoadMoreBean>() {
            @Override
            public void onResponse(Call<LoadMoreBean> call, Response<LoadMoreBean> response) {
                LoadMoreBean bean = response.body();
                for (LoadMoreLivesBean LoadMoreBean :bean.getData().getLives()) {
                    Log.d("-----", "" + LoadMoreBean.getTitle());
                }
                beanHttpCallBack.onSuccess(response.body());
            }
            @Override
            public void onFailure(Call<LoadMoreBean> call, Throwable t) {
                beanHttpCallBack.onFail();
            }
        });
    } //首页我的世界加载更多
    public void getWorldData(HashMap<String,String> params,final HttpCallBack<LoadMoreBean> beanHttpCallBack){
        Call<LoadMoreBean> homeBeanCall = RetrofitHelper
                .getInstance()
                .createRetrofitService(BeanService.class)
                .getWorld(params);
        homeBeanCall.enqueue(new Callback<LoadMoreBean>() {
            @Override
            public void onResponse(Call<LoadMoreBean> call, Response<LoadMoreBean> response) {
                LoadMoreBean bean = response.body();
                for (LoadMoreLivesBean LoadMoreBean :bean.getData().getLives()) {
                    Log.d("-----", "" + LoadMoreBean.getTitle());
                }
                beanHttpCallBack.onSuccess(response.body());
            }
            @Override
            public void onFailure(Call<LoadMoreBean> call, Throwable t) {
                beanHttpCallBack.onFail();
            }
        });
    } //首页王者荣耀加载更多LoadMoreKingBean
    public void getKingData(HashMap<String,String> params,final HttpCallBack<LoadMoreBean> beanHttpCallBack){
        Call<LoadMoreBean> homeBeanCall = RetrofitHelper
                .getInstance()
                .createRetrofitService(BeanService.class)
                .getKing(params);
        homeBeanCall.enqueue(new Callback<LoadMoreBean>() {
            @Override
            public void onResponse(Call<LoadMoreBean> call, Response<LoadMoreBean> response) {
                LoadMoreBean bean = response.body();
                for (LoadMoreLivesBean LoadMoreBean :bean.getData().getLives()) {
                    Log.d("-----", "" + LoadMoreBean.getTitle());
                }
                beanHttpCallBack.onSuccess(response.body());
            }
            @Override
            public void onFailure(Call<LoadMoreBean> call, Throwable t) {
                beanHttpCallBack.onFail();
            }
        });
    } //首页球球大作战加载更多
    public void getBallData(HashMap<String,String> params,final HttpCallBack<LoadMoreBean> beanHttpCallBack){
        Call<LoadMoreBean> homeBeanCall = RetrofitHelper
                .getInstance()
                .createRetrofitService(BeanService.class)
                .getBall(params);
        homeBeanCall.enqueue(new Callback<LoadMoreBean>() {
            @Override
            public void onResponse(Call<LoadMoreBean> call, Response<LoadMoreBean> response) {
                LoadMoreBean bean = response.body();
                for (LoadMoreLivesBean LoadMoreBean :bean.getData().getLives()) {
                    Log.d("-----", "" + LoadMoreBean.getTitle());
                }
                beanHttpCallBack.onSuccess(response.body());
            }
            @Override
            public void onFailure(Call<LoadMoreBean> call, Throwable t) {
                beanHttpCallBack.onFail();
            }
        });
    } //首页最热房间加载更多
    public void getHotRoomData(HashMap<String,String> params,final HttpCallBack<LoadMoreBean> beanHttpCallBack){
        Call<LoadMoreBean> homeBeanCall = RetrofitHelper
                .getInstance()
                .createRetrofitService(BeanService.class)
                .getHotRoom(params);
        homeBeanCall.enqueue(new Callback<LoadMoreBean>() {
            @Override
            public void onResponse(Call<LoadMoreBean> call, Response<LoadMoreBean> response) {
                LoadMoreBean bean = response.body();
                for (LoadMoreLivesBean LoadMoreBean :bean.getData().getLives()) {
                    Log.d("-----", "" + LoadMoreBean.getTitle());
                }
                beanHttpCallBack.onSuccess(response.body());
            }
            @Override
            public void onFailure(Call<LoadMoreBean> call, Throwable t) {
                beanHttpCallBack.onFail();
            }
        });
    }
    //视频播放
    public void getPlayVideoData(String roomId,HashMap<String,String> params,final HttpCallBack<PlayVideoBean> beanHttpCallBack){
        Call<PlayVideoBean> playVideoBeanCall = RetrofitHelper
                .getInstance()
                .createRetrofitService(BeanService.class)
                .getPlayVideo(roomId,params);
        playVideoBeanCall.enqueue(new Callback<PlayVideoBean>() {
            @Override
            public void onResponse(Call<PlayVideoBean> call, Response<PlayVideoBean> response) {
                PlayVideoBean bean = response.body();
                //for (PlayVideoDataBean LoadMoreBean :bean.getData()) {
                    Log.d("DDDDD", "" + bean.getData().getPhoneModel());
              //  }
                beanHttpCallBack.onSuccess(response.body());
            }
            @Override
            public void onFailure(Call<PlayVideoBean> call, Throwable t) {
                beanHttpCallBack.onFail();
            }
        });
    }


}

